import time

import allure
from selenium.webdriver.common.by import By

from bazhuayun.page.base_octopus_cloud import BaseOctopusCloud
from bazhuayun.utils.log_utils import logger


class HomePage(BaseOctopusCloud):
    _CLICK_WAREHOUSE = By.XPATH, '//*[text()="仓库(供应商)管理"]'
    _CLICK_WAREHOUSE1 = By.XPATH, '//*[text()="仓库(供应商)"]'
    _CLICK_ADD = By.XPATH, '//*[text()="添加仓库（供应商）"]'
    _CLICK_WO_YI_ZHI_XIAO = By.CSS_SELECTOR, '.el-button.el-button--default.el-button--small.el-button--primary '
    _CLICK_WAREHOUSE_NAME = By.XPATH, '(//*[@class="el-input__inner"])[1]'
    _CLICK_FOUND = By.XPATH, '//*[text()="查询"]'
    _CONFIRM_TEXT = By.XPATH, '(//*[@class="cell"])[28]'
    _CLICK_DELETE = By.XPATH, '//*[text()="删除"]'
    _CLICK_IDENTIFY = By.XPATH, '(//*[@class="el-button el-button--default el-button--small el-button--primary "])'
    _DELETE_TEXT = By.XPATH, '//*[text()="删除成功"]'

    @allure.step("进入添加仓库页面")
    def homepage(self):
        # 点击仓库管理
        self.find_ele(*self._CLICK_WAREHOUSE).click()
        # 点击仓库
        self.find_ele(*self._CLICK_WAREHOUSE1).click()
        # 点击添加按钮
        time.sleep(2)
        self.find_ele(*self._CLICK_ADD).click()
        logger.info("进入添加仓库页面")

        from bazhuayun.page.home_page_add import HomePageAdd
        return HomePageAdd(self.driver)

    @allure.step("查找添加的仓库")
    def found_home(self, name):
        # 点击我已知晓
        self.find_ele(*self._CLICK_WO_YI_ZHI_XIAO).click()
        # 点击仓库名称
        self.find_ele(*self._CLICK_WAREHOUSE_NAME).click()
        self.find_ele(*self._CLICK_WAREHOUSE_NAME).send_keys(name)
        # 点击查询
        self.find_ele(*self._CLICK_FOUND).click()
        # 确定文本
        res = self.find_ele(*self._CONFIRM_TEXT)
        time.sleep(5)
        # 点击删除
        self.find_ele(*self._CLICK_DELETE).click()
        # 点击确认
        self.find_ele(*self._CLICK_IDENTIFY).click()
        logger.info("查找添加仓库")
        return res

    @allure.step("删除添加的仓库")
    def delete_home(self, name):
        # 点击我已知晓
        self.find_ele(*self._CLICK_WO_YI_ZHI_XIAO).click()
        # 点击仓库名称
        self.find_ele(*self._CLICK_WAREHOUSE_NAME).click()
        self.find_ele(*self._CLICK_WAREHOUSE_NAME).send_keys(name)
        # 点击查询
        self.find_ele(*self._CLICK_FOUND).click()
        # 点击删除
        self.find_ele(*self._CLICK_DELETE).click()
        # 点击确认
        self.find_ele(*self._CLICK_IDENTIFY).click()
        # 确认文本
        res = self.find_ele(*self._DELETE_TEXT)
        logger.info("删除添加仓库")
        return res











